# Maintainer: Diego Sogari <diego.sogari@falker.com.br>

_realname=liblas
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8.0
pkgrel=1
pkgdesc="ASPRS LiDAR data translation toolset (mingw-w64)"
arch=('any')
url="http://www.liblas.org/"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-gdal" "${MINGW_PACKAGE_PREFIX}-laszip")
source=("${_realname}-${pkgver}.tar.gz::https://codeload.github.com/libLAS/libLAS/tar.gz/${pkgver}"
        "${_realname}-${pkgver}.patch")
sha256sums=('f438b639a4e7cd716051c0dcb3f96f2e932f29a715da8db3f61f90b658074036'
            'cf4e6a01c9a1ada863b6aaeb57ab4368d453d45877a480fe9d3ad45fcf015cc8')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/${_realname}-${pkgver}.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "../${_realname}-${pkgver}"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  export GDAL_DATA="${MINGW_PREFIX}/share/gdal"
  export PROJSO="${MINGW_PREFIX}/bin/libproj-9.dll"
  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
